package netty.demo.nio.byteBuffer;

import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.charset.StandardCharsets;

/**
 * @author Zed
 * @description 集中写入
 * @date 2022/10/22 16:35
 */
public class testGatheringWrites {
    public static void main(String[] args) {
        ByteBuffer b1 = StandardCharsets.UTF_8.encode("Hello");
        ByteBuffer b2 = StandardCharsets.UTF_8.encode("World");
        ByteBuffer b3 = StandardCharsets.UTF_8.encode("你好");
        try {
            FileChannel channel = new RandomAccessFile("words2.txt","rw").getChannel();
            channel.write(new ByteBuffer[]{b1,b2,b3});
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
